package com.object.oriented.exam.system8.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.object.oriented.exam.system5.entity.Answer;
import com.object.oriented.exam.system5.service.AnswerService;
import com.object.oriented.exam.system8.entity.Question;
import com.object.oriented.exam.system8.service.ErrorService;
import com.object.oriented.exam.system8.service.QuestionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @author ztz
 * @date 2023-06-20
 */
@Service
public class ErrorServiceImpl implements ErrorService {
    @Resource
    AnswerService answerService;

    @Resource
    QuestionService questionService;

    @Override
    public Page<Question> getErrorProblem(Long studentId, Long current, Long size) {
        // 获取错题
        Page<Answer> answerPage=answerService.getErrorAnswer(studentId,current,size);
        List<Answer> answers=answerPage.getRecords();
        List<Question> questionList =new LinkedList<>();

        // 根据错题，获取题目相关信息（答案，解析等）
        for(Answer answer:answers){
            Question question =questionService.getQuestion(answer);
            questionList.add(question);
        }

        Page<Question> errorPage=new Page<>(current,size);
        errorPage.setTotal(answerPage.getTotal());
        errorPage.setPages(answerPage.getPages());
        errorPage.setRecords(questionList);
        return errorPage;
    }

}
